/**
 * Created by CZ on 2017/5/3.
 */
module.exports = function ($scope,$rootScope,$localStorage,RequestService,$stateParams,$modal,commonConfig) {
    $rootScope.isShowFooter = false;
    //星星等级评分
    $scope.max = 5;
    $scope.ratingVal = 0;
    $scope.hoverVal = 0;//一般的话，ratingVal和hoverVal都写0就可以了。
    // $scope.readonly = false; 控制是否只是显示不控制
    $scope.onHover = function(val) {
        $scope.hoverVal = val;
    };
    $scope.onLeave = function() {
        $scope.hoverVal = $scope.ratingVal;
    };
    $scope.onChange = function(val) {
        $scope.ratingVal = val;
    };
    //过滤器
    $scope.TypeId = $stateParams.id;

    //排序控制
    $scope.sortNum = 1;
    var orderBy = ''; //初始化排序
    $scope.sort = function(id){
        $scope.sortNum = id;
        switch (id){
            case 1: orderBy ='user_number';  break;
            case 2: orderBy ='update_time';break;
            case 3: orderBy ='star_number'; break;
        }
        //获取排序数据
        $scope.getAppsList(orderBy,1);
    };
    //分页跳转
    $scope.goPage = function(){
        // console.log($scope.currentPage);
        $scope.getAppsList(orderBy,$scope.currentPage);
    };
    //手动输入跳转
    $scope.goPage2 = function(){
        // console.log($scope.currentPage);
        $scope.getAppsList(orderBy,$scope.PageNum);
    };

    $scope.getAppsList = function(orderBy,page){
        //获取应用列表
        RequestService.Request(commonConfig.cloudApi+'cloud/app?isOpen=1&status=1&pageSize=10&pageNum='+page+'&orderBy='+orderBy+'&appTypeId='+$scope.TypeId,'GET').then(function(res){
            console.log(res);
            $scope.AppsList = res.list;

            //分页控制
            $scope.maxSize = 5;
            $scope.totalItems = res.total;  //总数量
            $scope.totalPages = res.pages;   //总页数
            $scope.pageSize = 10; //每页显示数量
            $scope.currentPage = res.pageNum;
            $scope.PageNum = null;  //输入跳转
        },function(error){
            console.log(error);
        });
    };
    $scope.getAppsList('user_number',1);

    //添加应用到租户
    $scope.buyApp = function(){
        $modal.open({
            animation: true,
            templateUrl: './views/model/ExitModel.html',
            size: '',
            controller: function($scope,$modalInstance) {
                $scope.content = '您未登录，请先进行登录';
                $scope.ok = function () {
                    $rootScope.Login();
                    $modalInstance.close();
                };
                $scope.cancel = function(){
                    $modalInstance.close();
                }
            }
        });
    };
};